
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/utilities/misc.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:14 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Miscellaneous &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="misc.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="PKGDATA" href="pkgdata.html" />
    <link rel="prev" title="Memoization" href="memoization.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pkgdata.html" title="PKGDATA"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="memoization.html" title="Memoization"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Utilities</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Miscellaneous</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.utilities.misc">
<span id="miscellaneous"></span><h1>Miscellaneous<a class="headerlink" href="#module-sympy.utilities.misc" title="Permalink to this headline">¶</a></h1>
<p>Miscellaneous stuff that doesn’t really fit anywhere else.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.debug">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">debug</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L241-L247"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.debug" title="Permalink to this definition">¶</a></dt>
<dd><p>Print <code class="docutils literal notranslate"><span class="pre">*args</span></code> if SYMPY_DEBUG is True, else do nothing.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.debug_decorator">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">debug_decorator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L179-L238"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.debug_decorator" title="Permalink to this definition">¶</a></dt>
<dd><p>If SYMPY_DEBUG is True, it will print a nice execution tree with
arguments and results of all decorated functions, else do nothing.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.filldedent">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">filldedent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">w</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">70</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L20-L33"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.filldedent" title="Permalink to this definition">¶</a></dt>
<dd><p>Strips leading and trailing empty lines from a copy of <span class="math notranslate nohighlight">\(s\)</span>, then dedents,
fills and returns it.</p>
<p>Empty line stripping serves to deal with docstrings like this one that
start with a newline after the initial triple quote, inserting an empty
line at the beginning of the string.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.utilities.misc.strlines" title="sympy.utilities.misc.strlines"><code class="xref py py-obj docutils literal notranslate"><span class="pre">strlines</span></code></a>, <a class="reference internal" href="#sympy.utilities.misc.rawlines" title="sympy.utilities.misc.rawlines"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rawlines</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.find_executable">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">find_executable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">executable</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L250-L285"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.find_executable" title="Permalink to this definition">¶</a></dt>
<dd><p>Try to find ‘executable’ in the directories listed in ‘path’ (a
string listing directories separated by ‘os.pathsep’; defaults to
os.environ[‘PATH’]).  Returns the complete filename or None if not
found</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.func_name">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">func_name</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">short</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L288-L324"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.func_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Return function name of <span class="math notranslate nohighlight">\(x\)</span> (if defined) else the <span class="math notranslate nohighlight">\(type(x)\)</span>.
If short is True and there is a shorter alias for the result,
return the alias.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.misc</span> <span class="kn">import</span> <span class="n">func_name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">func_name</span><span class="p">(</span><span class="n">Matrix</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">&#39;MutableDenseMatrix&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">func_name</span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">&#39;StrictLessThan&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">func_name</span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">,</span> <span class="n">short</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="go">&#39;Lt&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.ordinal">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">ordinal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">num</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L465-L481"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.ordinal" title="Permalink to this definition">¶</a></dt>
<dd><p>Return ordinal number string of num, e.g. 1 becomes 1st.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.rawlines">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">rawlines</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L88-L168"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.rawlines" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a cut-and-pastable string that, when printed, is equivalent
to the input. Use this when there is more than one line in the
string. The string returned is formatted so it can be indented
nicely within tests; in some cases it is wrapped in the dedent
function which has to be imported from textwrap.</p>
<p class="rubric">Examples</p>
<p>Note: because there are characters in the examples below that need
to be escaped because they are themselves within a triple quoted
docstring, expressions below look more complicated than they would
be if they were printed in an interpreter window.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.misc</span> <span class="kn">import</span> <span class="n">rawlines</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">TableForm</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">TableForm</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">]],</span> <span class="n">headings</span><span class="o">=</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;bee&#39;</span><span class="p">])))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rawlines</span><span class="p">(</span><span class="n">s</span><span class="p">))</span>
<span class="go">(</span>
<span class="go">    &#39;a bee\n&#39;</span>
<span class="go">    &#39;-----\n&#39;</span>
<span class="go">    &#39;1 10 &#39;</span>
<span class="go">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rawlines</span><span class="p">(</span><span class="s1">&#39;&#39;&#39;this</span>
<span class="gp">... </span><span class="s1">that&#39;&#39;&#39;</span><span class="p">))</span>
<span class="go">dedent(&#39;&#39;&#39;\</span>
<span class="go">    this</span>
<span class="go">    that&#39;&#39;&#39;)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rawlines</span><span class="p">(</span><span class="s1">&#39;&#39;&#39;this</span>
<span class="gp">... </span><span class="s1">that</span>
<span class="gp">... </span><span class="s1">&#39;&#39;&#39;</span><span class="p">))</span>
<span class="go">dedent(&#39;&#39;&#39;\</span>
<span class="go">    this</span>
<span class="go">    that</span>
<span class="go">    &#39;&#39;&#39;)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;this</span>
<span class="gp">... </span><span class="s2">is a triple &#39;&#39;&#39;</span>
<span class="gp">... </span><span class="s2">&quot;&quot;&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rawlines</span><span class="p">(</span><span class="n">s</span><span class="p">))</span>
<span class="go">dedent(&quot;&quot;&quot;\</span>
<span class="go">    this</span>
<span class="go">    is a triple &#39;&#39;&#39;</span>
<span class="go">    &quot;&quot;&quot;)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rawlines</span><span class="p">(</span><span class="s1">&#39;&#39;&#39;this</span>
<span class="gp">... </span><span class="s1">that</span>
<span class="gp">... </span><span class="s1">    &#39;&#39;&#39;</span><span class="p">))</span>
<span class="go">(</span>
<span class="go">    &#39;this\n&#39;</span>
<span class="go">    &#39;that\n&#39;</span>
<span class="go">    &#39;    &#39;</span>
<span class="go">)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.utilities.misc.filldedent" title="sympy.utilities.misc.filldedent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">filldedent</span></code></a>, <a class="reference internal" href="#sympy.utilities.misc.strlines" title="sympy.utilities.misc.strlines"><code class="xref py py-obj docutils literal notranslate"><span class="pre">strlines</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.replace">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">replace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">reps</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L350-L389"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.replace" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">string</span></code> with all keys in <code class="docutils literal notranslate"><span class="pre">reps</span></code> replaced with
their corresponding values, longer strings first, irrespective
of the order they are given.  <code class="docutils literal notranslate"><span class="pre">reps</span></code> may be passed as tuples
or a single mapping.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.misc</span> <span class="kn">import</span> <span class="n">replace</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;oo&#39;</span><span class="p">:</span> <span class="s1">&#39;ar&#39;</span><span class="p">,</span> <span class="s1">&#39;f&#39;</span><span class="p">:</span> <span class="s1">&#39;b&#39;</span><span class="p">})</span>
<span class="go">&#39;bar&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;spamham sha&quot;</span><span class="p">,</span> <span class="p">(</span><span class="s2">&quot;spam&quot;</span><span class="p">,</span> <span class="s2">&quot;eggs&quot;</span><span class="p">),</span> <span class="p">(</span><span class="s2">&quot;sha&quot;</span><span class="p">,</span><span class="s2">&quot;md5&quot;</span><span class="p">))</span>
<span class="go">&#39;eggsham md5&#39;</span>
</pre></div>
</div>
<p>There is no guarantee that a unique answer will be
obtained if keys in a mapping overlap (i.e. are the same
length and have some identical sequence at the
beginning/end):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">reps</span> <span class="o">=</span> <span class="p">[</span>
<span class="gp">... </span>    <span class="p">(</span><span class="s1">&#39;ab&#39;</span><span class="p">,</span> <span class="s1">&#39;x&#39;</span><span class="p">),</span>
<span class="gp">... </span>    <span class="p">(</span><span class="s1">&#39;bc&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;abc&#39;</span><span class="p">,</span> <span class="o">*</span><span class="n">reps</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;xc&#39;</span><span class="p">,</span> <span class="s1">&#39;ay&#39;</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r921"><span class="brackets"><a class="fn-backref" href="#id1">R921</a></span></dt>
<dd><p><a class="reference external" href="https://stackoverflow.com/questions/6116978/python-replace-multiple-strings">https://stackoverflow.com/questions/6116978/python-replace-multiple-strings</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.strlines">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">strlines</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">64</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">short</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L36-L85"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.strlines" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a cut-and-pastable string that, when printed, is
equivalent to the input.  The lines will be surrounded by
parentheses and no line will be longer than c (default 64)
characters. If the line contains newlines characters, the
<span class="math notranslate nohighlight">\(rawlines\)</span> result will be returned.  If <code class="docutils literal notranslate"><span class="pre">short</span></code> is True
(default is False) then if there is one line it will be
returned without bounding parentheses.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.misc</span> <span class="kn">import</span> <span class="n">strlines</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="s1">&#39;this is a long string that should be broken into shorter lines&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">strlines</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="mi">40</span><span class="p">))</span>
<span class="go">(</span>
<span class="go">&#39;this is a long string that should be b&#39;</span>
<span class="go">&#39;roken into shorter lines&#39;</span>
<span class="go">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">==</span> <span class="p">(</span>
<span class="gp">... </span><span class="s1">&#39;this is a long string that should be b&#39;</span>
<span class="gp">... </span><span class="s1">&#39;roken into shorter lines&#39;</span>
<span class="gp">... </span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.utilities.misc.filldedent" title="sympy.utilities.misc.filldedent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">filldedent</span></code></a>, <a class="reference internal" href="#sympy.utilities.misc.rawlines" title="sympy.utilities.misc.rawlines"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rawlines</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.utilities.misc.translate">
<span class="sig-prename descclassname"><span class="pre">sympy.utilities.misc.</span></span><span class="sig-name descname"><span class="pre">translate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/utilities/misc.py#L392-L462"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.utilities.misc.translate" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">s</span></code> where characters have been replaced or deleted.</p>
<p class="rubric">Syntax</p>
<dl class="simple">
<dt>translate(s, None, deletechars):</dt><dd><p>all characters in <code class="docutils literal notranslate"><span class="pre">deletechars</span></code> are deleted</p>
</dd>
<dt>translate(s, map [,deletechars]):</dt><dd><p>all characters in <code class="docutils literal notranslate"><span class="pre">deletechars</span></code> (if provided) are deleted
then the replacements defined by map are made; if the keys
of map are strings then the longer ones are handled first.
Multicharacter deletions should have a value of ‘’.</p>
</dd>
<dt>translate(s, oldchars, newchars, deletechars)</dt><dd><p>all characters in <code class="docutils literal notranslate"><span class="pre">deletechars</span></code> are deleted
then each character in <code class="docutils literal notranslate"><span class="pre">oldchars</span></code> is replaced with the
corresponding character in <code class="docutils literal notranslate"><span class="pre">newchars</span></code></p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.utilities.misc</span> <span class="kn">import</span> <span class="n">translate</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">abc</span> <span class="o">=</span> <span class="s1">&#39;abc&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">translate</span><span class="p">(</span><span class="n">abc</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">)</span>
<span class="go">&#39;bc&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">translate</span><span class="p">(</span><span class="n">abc</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="s1">&#39;x&#39;</span><span class="p">},</span> <span class="s1">&#39;c&#39;</span><span class="p">)</span>
<span class="go">&#39;xb&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">translate</span><span class="p">(</span><span class="n">abc</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;abc&#39;</span><span class="p">:</span> <span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="s1">&#39;y&#39;</span><span class="p">})</span>
<span class="go">&#39;x&#39;</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">translate</span><span class="p">(</span><span class="s1">&#39;abcd&#39;</span><span class="p">,</span> <span class="s1">&#39;ac&#39;</span><span class="p">,</span> <span class="s1">&#39;AC&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">)</span>
<span class="go">&#39;AbC&#39;</span>
</pre></div>
</div>
<p>There is no guarantee that a unique answer will be
obtained if keys in a mapping overlap are the same
length and have some identical sequences at the
beginning/end:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">translate</span><span class="p">(</span><span class="n">abc</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;ab&#39;</span><span class="p">:</span> <span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;bc&#39;</span><span class="p">:</span> <span class="s1">&#39;y&#39;</span><span class="p">})</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;xc&#39;</span><span class="p">,</span> <span class="s1">&#39;ay&#39;</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="memoization.html"
                        title="previous chapter">Memoization</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="pkgdata.html"
                        title="next chapter">PKGDATA</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/utilities/misc.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pkgdata.html" title="PKGDATA"
             >next</a> |</li>
        <li class="right" >
          <a href="memoization.html" title="Memoization"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Utilities</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Miscellaneous</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/utilities/misc.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:14 GMT -->
</html>